package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.model.TeamUser;
import com.keyancompany.zhongbaopingtai.weight.CircleOptionsPopup;
import com.keyancompany.zhongbaopingtai.weight.TeamOptionsPopup;

/**
 * 我的团队 or  我参与的团队
 * <p>
 * Created by firefox on 2016/6/18.
 */
public class MyTeamAdapter extends ListAdapter<TeamUser> {

    TeamOptionsPopup optionsPopup;
    CircleOptionsPopup circleOptionsPopup;
    boolean isMyTeam = false;

    public MyTeamAdapter(Context ctx, boolean isMyTeam) {
        super(ctx);
        this.isMyTeam = isMyTeam;
    }
    @Override
    public int getContentViewId() {
        return R.layout.item_team_circle;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {

        return new TeamCircleHolder(contentView);
    }

    @Override
    public void setItemView(final int position, HolderView contentView, final TeamUser item) {
        TeamCircleHolder hold = (TeamCircleHolder) contentView;
        hold.content.setText(item.getTeamName());
        if (isMyTeam)
            hold.name.setVisibility(View.GONE);
        else
            hold.name.setVisibility(View.VISIBLE);
        hold.more.setVisibility(View.GONE);
//        hold.more.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showTeamPop(v, position, item);
//            }
//
//        });
    }


    private void showTeamPop(View v, final int position, final TeamUser item) {
        if (optionsPopup == null) {
            optionsPopup = new TeamOptionsPopup(ctx);
            if (isMyTeam)
                optionsPopup.hideTeamsettlement();
        }
        optionsPopup.setTeamUser(item, position);
        optionsPopup.showAtLocation(v, Gravity.CENTER, 0, 0);
    }

    public class TeamCircleHolder extends HolderView {
        private ImageView more;
        private TextView name;
        private TextView content;
        private TextView createTime;

        public TeamCircleHolder(View view) {
            more = (ImageView) view.findViewById(R.id.item_team_circle_more);
            content = (TextView) view.findViewById(R.id.item_team_content);
            createTime = (TextView) view.findViewById(R.id.create_time);
            name = (TextView) view.findViewById(R.id.create_man);

        }
    }
}
